<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;
use App\Rules\GreenContent;

class CommentRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $method = $this->method();
        $rules = [];
        switch ($method) {
            case 'POST':
                $rules['content'] = ['required', 'between:6,120', new GreenContent];
                $rules['comment_id'] = 'nullable|sometimes|integer';
                break;

            default:
                # code...
                break;
        }
        return $rules;
    }
}
